package com.eaoa.uc.account.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.uc.account.bo.AccountModifyBO;
import com.eaoa.uc.account.form.AccountForm;
import com.eaoa.uc.customer.bo.CustomerModifyBO;
import com.eaoa.vo.pub.PubAccount;
import com.eaoa.vo.pub.PubCustomer;
import com.stony.core.struts.action.BaseAction;

public class AccountRegisterAccountAction extends BaseAction {

	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		AccountForm aform = (AccountForm) form;
		PubAccount account = aform.getVo();

		PubCustomer customer= new PubCustomer();
		customer.setName(account.getName());
		customer.setNameshort(account.getName());

		CustomerModifyBO customerModifyBO = new CustomerModifyBO(customer);
		customerModifyBO.execute();
		Long customerno = customerModifyBO.getCustomerno();
		customer.setCustomerno(customerno);
		
		account.setCompany(customer);
		AccountModifyBO accountModifyBO = new AccountModifyBO(account);
		accountModifyBO.execute();
		
		if(StringUtils.isNotBlank(aform.getIspersonal())  //not personal
				&& aform.getIspersonal().equals("N")){
			request.setAttribute("customerno", customerno);
			return mapping.findForward("success_customer");
		}

		return mapping.findForward("success");

	}
}